<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // var jsonstr = '{ "name": "王麻子", "age": 24 }';
    // 键名和键值都需要引号，且是字符串型

    // 对象转换成json数据
    var obj = { name: "张三", age: 20 };
    var jsonstr = JSON.stringify(obj);
    console.log(jsonstr);

    // json数据转化为对象
    var jsonstr = '[{ "name": "张三", "age": 20 },{"height":178}]';
    var obj = JSON.parse(jsonstr);
    console.log(obj);
  </script>
</html>
